package com.myproject.timer;

import com.myproject.controller.TimerController;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MyTimerTask extends TimerTask {
    @Override
    public void run() {
        Thread thread = Thread.currentThread();
        if (TimerController.currThread!=thread){
            TimerController.currThread = thread;
        }
        System.out.println(thread+":"+thread.getState());
    }

    public static void main(String[] args) throws IOException {

        int COUNT_BITS = Integer.SIZE - 3;
        int CAPACITY   = (1 << COUNT_BITS) - 1;
        int RUNNING    = -1 << COUNT_BITS;
        int SHUTDOWN   =  0 << COUNT_BITS;
        int STOP       =  1 << COUNT_BITS;
        int TIDYING    =  2 << COUNT_BITS;
        int TERMINATED =  3 << COUNT_BITS;
        int ctrl = RUNNING | 0;
        int worker = ctrl & CAPACITY;
        System.out.println(RUNNING);
        System.out.println(SHUTDOWN);
        System.out.println(STOP);
        System.out.println(TIDYING);
        System.out.println(TERMINATED);
        System.out.println(ctrl);
        System.out.println(worker);

        /*ThreadPoolExecutor executor1 = new ThreadPoolExecutor(64, 64, 60L, TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(10000), (Runnable r, ThreadPoolExecutor executor) -> {
            if (!executor.isShutdown()) {
                try {
                    executor.getQueue().put(r);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
        });
        executor1.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println();
            }
        });
        executor1.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println();
            }
        });

        Timer timer = new Timer();
        timer.schedule(new MyTimerTask(),0,5000);
        java.util.Scanner sc = new java.util.Scanner(System.in);
        while (true){
            String str = sc.next();
            if ("get".equals(str)){
                System.out.println(TimerController.currThread.getState().toString());
            }
        }*/

    }
}
